home *** CD-ROM | disk | FTP | other *** search
/ SPACE 2 / SPACE - Library 2 - Volume 1.iso / program / 316 / libsrc / flonum.s < prev    next >
Encoding:
Text File  |  1988-10-20  |  15.3 KB  |  804 lines

  1. #
  2. #
  3. #    Floating point support code.  What a crock!
  4. #
  5. #    A float looks like:
  6. #
  7. #    |S|E.x.p ... |M.a.n.t.i.s.s.a ... |
  8. #    +-+----------+--------------------+
  9. #
  10. #    where s is the sign bit, Exp is 8 bits of exponent, interpreted
  11. #    as E + 126, and Mantissa is 23 bits of fraction, with a
  12. #    hidden bit.  The point is to the left of the hidden bit.
  13. #    Doubles have another word of mantissa following.
  14. #
  15. #    All these routines have calling sequences like c routines,
  16. #    ie args on stack in backwards order, return values in d0
  17. #
  18.  
  19. # union double_di { double d; int i[2]; };
  20. # union flt_or_int { int i; float f; };
  21.  
  22. # #ifdef L_divdf3
  23. # double
  24. # _divdf3 (a, b)
  25. #      double a, b;
  26. # {
  27. #   return a / b;
  28. # }
  29. # #endif
  30. .text
  31.     .even
  32. .globl __divdf3
  33. __divdf3:
  34.     movel    sp@(12),sp@-
  35.     movel    sp@(8),sp@-
  36.     jsr    __divsf3
  37.     addql    #8,sp
  38.     clrl    d1        | kludge!!!
  39.     rts            | sigh
  40. # #ifdef L_muldf3
  41. # double
  42. # _muldf3 (a, b)
  43. #      double a, b;
  44. # {
  45. #   return a * b;
  46. # }
  47. # #endif
  48.  
  49. .text
  50.     .even
  51. .globl __muldf3
  52. __muldf3:
  53.     movel    sp@(12),sp@-
  54.     movel    sp@(8),sp@-
  55.     jsr    __mulsf3
  56.     addql    #8,sp
  57.     clrl    d1        | kludge!!!
  58.     rts            | sigh
  59. # #ifdef L_negdf2
  60. # double
  61. # _negdf2 (a)
  62. #      double a;
  63. # {
  64. #   return -a;
  65. # }
  66. # #endif
  67.  
  68. .text
  69.     .even
  70. .globl __negdf2
  71. __negdf2:
  72.     movel    sp@(8),d1        | get a lo
  73.     movel    sp@(4),d0        | get a hi
  74.     beq    negdf2_z        | zero, leave it
  75.     eorl    #0x80000000,d0        | twiddle sign
  76. negdf2_z:
  77.     rts
  78. # #ifdef L_adddf3
  79. # double
  80. # _adddf3 (a, b)
  81. #      double a, b;
  82. # {
  83. #   return a + b;
  84. # }
  85. # #endif
  86.  
  87. .text
  88.     .even
  89. .globl __adddf3
  90. __adddf3:
  91.     movel    sp@(12),sp@-
  92.     movel    sp@(8),sp@-
  93.     jsr    __addsf3
  94.     addql    #8,sp
  95.     clrl    d1        | kludge!!!
  96.     rts            | sigh
  97. # #ifdef L_subdf3
  98. # double
  99. # _subdf3 (a, b)
  100. #      double a, b;
  101. # {
  102. #   return a - b;
  103. # }
  104. # #endif
  105.  
  106. .text
  107.     .even
  108. .globl __subdf3
  109. __subdf3:
  110.     movel    sp@(12),sp@-
  111.     movel    sp@(8),sp@-
  112.     jsr    __subsf3
  113.     addql    #8,sp
  114.     clrl    d1        | kludge!!!
  115.     rts            | sigh
  116. # #ifdef L_cmpdf2
  117. # int
  118. # _cmpdf2 (a, b)
  119. #      double a, b;
  120. # {
  121. #   if (a > b)
  122. #     return 1;
  123. #   else if (a < b)
  124. #     return -1;
  125. #   return 0;
  126. # }
  127. # #endif
  128.  
  129. .text
  130.     .even
  131. .globl __cmpdf2
  132. __cmpdf2:
  133.     movel    sp@(4),d0    | get b hi
  134.     movel    sp@(12),d1    | get a hi
  135. |
  136. | crockery.  If both neg and not equal, this algorithm lose.  find a better one!
  137. |
  138.     bpl    cmpdf2_p
  139.     tstl    d0
  140.     bpl    cmpdf2_p
  141.     cmpl    d1,d0
  142.     bgt    cmpdf2_m
  143.     blt    cmpdf2_1
  144.     beq    cmpdf2_z
  145. cmpdf2_p:
  146.     cmpl    d1,d0        | get a hi
  147.     beq    cmpdf2_z    | if eq, return 0
  148.     bgt    cmpdf2_1    | if greater, return 1
  149. cmpdf2_m:
  150.     movel    #-1,d0        | else return -1
  151.     rts
  152. cmpdf2_z:
  153.     clrl    d0
  154.     rts
  155. cmpdf2_1:
  156.     movel    #1,d0
  157.     rts            | sigh
  158. # #ifdef L_fixunsdfsi
  159. # _fixunsdfsi (a)
  160. #      double a;
  161. # {
  162. #   return (unsigned int) a;
  163. # }
  164. # #endif
  165.  
  166. .text
  167.     .even
  168. .globl __fixunsdfsi
  169. __fixunsdfsi:
  170.     clrl d0
  171.     clrl d1
  172.     rts            | sigh
  173. # #ifdef L_fixunsdfdi
  174. # double
  175. # _fixunsdfdi (a)
  176. #      double a;
  177. # {
  178. #   union double_di u;
  179. #   u.i[LOW] = (unsigned int) a;
  180. #   u.i[HIGH] = 0;
  181. #   return u.d;
  182. # }
  183. # #endif
  184.  
  185. .text
  186.     .even
  187. .globl __fixunsdfdi
  188. __fixunsdfdi:
  189.     clrl d0
  190.     clrl d1
  191.     rts            | sigh
  192. # #ifdef L_fixdfsi
  193. # _fixdfsi (a)
  194. #      double a;
  195. # {
  196. #   return (int) a;
  197. # }
  198. # #endif
  199.  
  200. .text
  201.     .even
  202. .globl __fixdfsi
  203. __fixdfsi:
  204.     link    a6,#0
  205.     movel    d2,sp@-        | save reg
  206.     clrl    d2        | sign flag
  207.     movel    a6@(8),d0    | get the float
  208.     beq    fixdfsi_ret
  209.     bpl    fixdfsi_1
  210.     addql    #1,d2
  211. fixdfsi_1:
  212.     movel    d0,d1        | snag the exp
  213.     lsrl    #7,d1
  214.     lsrl    #8,d1
  215.     lsrl    #8,d1
  216.     andl    #0xFF,d1
  217.     subl    #126,d1
  218.     andl    #0x7FFFFF,d0    | zap cruft
  219.     orl    #0x800000,d0    | put back hidden bit
  220. |
  221. | at this point the mantissa looks like 2^24 * integer value.
  222. | if Exp is 24, we're done.  If it's less, we shift right,
  223. | else left
  224. |
  225. fixdfsi_2:
  226.     cmpl    #24,d1
  227.     beq    fixdfsi_4    | we're done
  228.     bmi    fixdfsi_3    | less, shift right
  229.     lsll    #1,d0        | greater, shift it left one
  230.     subql    #1,d1        | and dec exp
  231.     bra    fixdfsi_2
  232. fixdfsi_3:
  233.     lsrl    #1,d0        | shift right one
  234.     addql    #1,d1        | and inc exp
  235.     bra    fixdfsi_2
  236. fixdfsi_4:
  237.     tstl    d2        | negative?
  238.     beq    fixdfsi_ret
  239.     negl    d0
  240. fixdfsi_ret:
  241.     movel    sp@+,d2        | get d2 back
  242.     unlk    a6
  243.     rts
  244. # #ifdef L_fixdfdi
  245. # double
  246. # _fixdfdi (a)
  247. #      double a;
  248. # {
  249. #   union double_di u;
  250. #   u.i[LOW] = (int) a;
  251. #   u.i[HIGH] = (int) a < 0 ? -1 : 0;
  252. #   return u.d;
  253. # }
  254. # #endif
  255.  
  256. .text
  257.     .even
  258. .globl __fixdfdi
  259. __fixdfdi:
  260.     clrl d0
  261.     clrl d1
  262.     rts            | sigh
  263. # #ifdef L_floatsidf
  264. # double
  265. # _floatsidf (a)
  266. #      int a;
  267. # {
  268. #   return (double) a;
  269. # }
  270. # #endif
  271.  
  272. .text
  273.     .even
  274. .globl __floatsidf
  275. __floatsidf:
  276.     link    a6,#0        | set up frame
  277.     movel    d2,sp@-        | save d2; sign flag
  278.     clrl    d2        | not negative yet
  279.     movel    #24,d1        | exponent so far
  280.     movel    a6@(8),d0    | get the int
  281.     beq    floatsidf_ret    | zero?
  282.     bpl    floatsidf_1    | pos, it's ok
  283.     negl    d0        | negate it
  284.     addql    #1,d2        | bump sign
  285. floatsidf_1:
  286. |
  287. | normalize right if necessary
  288. |
  289.     cmpl    #0xFFFFFF,d0    | too big?
  290.     ble    floatsidf_2    | nope, see if need to slide left
  291.     addql    #1,d1        | bump exp
  292.     lsrl    #1,d0        | and slide mantissa right one
  293.     bra    floatsidf_1
  294. floatsidf_2:
  295.     btst    #23,d0        | got a bit up here yet?
  296.     bne    floatsidf_3    | nope, go left
  297.     subql    #1,d1        | dec exp
  298.     lsll    #1,d0        | and slide mantissa left one
  299.     bra    floatsidf_2
  300. floatsidf_3:
  301. |
  302. | now put it all together
  303. |
  304.     andl    #0x7FFFFF,d0    | zap hidden bit
  305.     addl    #126,d1        | offset exp
  306.     andl    #0xFF,d1    | trim it
  307.     lsll    #8,d1        | shift up
  308.     lsll    #8,d1
  309.     lsll    #7,d1
  310.     orl    d1,d0        | stuff it in
  311.     tstl    d2        | negative?
  312.     beq    floatsidf_ret
  313.     orl    #0x80000000,d0
  314. floatsidf_ret:
  315.     movel    sp@+,d2
  316.     clrl    d1        | ???
  317.     unlk    a6
  318.     rts            | sigh
  319. # #ifdef L_floatdidf
  320. # double
  321. # _floatdidf (u)
  322. #      union double_di u;
  323. # {
  324. #   register double hi
  325. #     = ((double) u.i[HIGH]) * (double) 0x10000 * (double) 0x10000;
  326. #   register double low = (unsigned int) u.i[LOW];
  327. #   return hi + low;
  328. # }
  329. # #endif
  330.  
  331. .text
  332.     .even
  333. .globl __floatdidf
  334. __floatdidf:
  335.     clrl d0
  336.     clrl d1
  337.     rts            | sigh
  338. # #define INTIFY(FLOATVAL)  (intify.f = (FLOATVAL), intify.i)
  339. # #ifdef L_addsf3
  340. # int
  341. # _addsf3 (a, b)
  342. #      union flt_or_int a, b;
  343. # {
  344. #   union flt_or_int intify;
  345. #   return INTIFY (a.f + b.f);
  346. # }
  347. # #endif
  348.  
  349. .text
  350.     .even
  351. .globl __addsf3
  352. __addsf3:
  353.     link    a6,#0        | don't need any locals
  354.     moveml    #0x3F00,sp@-    | save all data registers
  355.     movel    a6@(8),d0    | get a
  356.     beq    addsf_ret_b    |  zero .. just return b
  357.     movel    #23,d6        | shift count
  358.     movel    d0,d2        | get the exponent
  359.     lsrl    d6,d2        | and shift right
  360.     andl    #0xFF,d2    | no sign bit
  361.     subl    #126,d2        | offset the exponent
  362.     movel    a6@(12),d1    | get b
  363.     beq    addsf_ret_a
  364.     movel    d1,d3        | get the exponent for b
  365.     lsrl    d6,d3        | and shift right, with implicit extend
  366.     andl    #0xFF,d3    | make sure we didn't get a sign bit
  367.     subl    #126,d3        | off set this one too
  368.  
  369.     andl    #0x7FFFFF,d0    | mask a for mantissa
  370.     orl    #0x800000,d0    | and put in hidden bit
  371.     tstl    a6@(8)        | test the original value
  372.     bpl    addsf_1        | pos, ok
  373.     negl    d0        | neg, negate the mantissa
  374. addsf_1:
  375.     andl    #0x7FFFFF,d1    | mask b for mantissa
  376.     orl    #0x800000,d1    | ditto
  377.     tstl    a6@(12)        | test ...
  378.     bpl    addsf_2
  379.     negl    d1        | negate this one
  380. addsf_2:
  381.     cmpl    d2,d3        | compare Ea to Eb
  382.     blt    addsf_3        | Ea > Eb
  383.  
  384.     movel    d3,d5        | get Eb
  385.     subl    d2,d5        | subtract Ea
  386.     asrl    d5,d0        |  yielding count to shift Ma right
  387.     movel    d3,d5        | use this as resultant exponent
  388.     bra    addsf_4        | and go rejoin common part
  389. addsf_3:
  390.     movel    d2,d5        | get Ea
  391.     subl    d3,d5        | subtract Eb
  392.     asrl    d5,d1        |  yielding count to shift Mb right
  393.     movel    d2,d5        | use this as resultant exponent
  394.  
  395. addsf_4:
  396.     clrl    d7        | zap sign flag
  397.     addl    d1,d0        | add Mb to Ma
  398.  
  399.  
  400.     beq    addsf_z        | zero? ok, go return zero
  401.     bpl    addsf_5        | positive? ok, go scale it
  402.     negl    d0        | negate Mr
  403.     movel    #1,d7        | remember sign
  404. addsf_5:
  405.     btst    #24,d0        | carry?
  406.     beq    addsf_6        | nope, it's ok as is
  407.     asrl    #1,d0        | shift right one
  408.     addql    #1,d5        | inc exp
  409.  
  410. | zzz check for overflow in here someplace
  411.  
  412. addsf_6:
  413.     btst    #23,d0        | got a bit in the right place yet?
  414.     bne    addsf_7        | yes, we're done
  415.     lsll    #1,d0        | shift left one
  416.     subql    #1,d5        | dec exponent
  417.     bra    addsf_6
  418. addsf_7:
  419.     andl    #0x7FFFFF,d0    | zap out hidden bit
  420.     addl    #126,d5        | add offset to exp
  421.     andl    #0xFF,d5    | zap to 8 bits
  422.     movel    #23,d6        | shift count
  423.     lsll    d6,d5        | shift the exp up
  424.     orl    d5,d0        | stick the exp in
  425.     tstl    d7        | negative?
  426.     beq    addsf_ret_a
  427.     orl    #0x80000000,d0    | yup, negate it
  428.     bra    addsf_ret_a
  429. addsf_z:
  430.     clrl    d0
  431.     bra    addsf_ret_a
  432. addsf_ret_b:
  433.     movel    a6@(12),d0
  434. addsf_ret_a:
  435.     moveml    sp@+,#0x00FC    | snarf back all regs
  436.     unlk    a6
  437.     rts            | sigh
  438. # #ifdef L_negsf2
  439. # int
  440. # _negsf2 (a)
  441. #      union flt_or_int a;
  442. # {
  443. #   union flt_or_int intify;
  444. #   return INTIFY (-a.f);
  445. # }
  446. # #endif
  447.  
  448. .text
  449.     .even
  450. .globl __negsf2
  451. __negsf2:
  452.     movel    sp@(4),d0
  453.     beq    negsf2_z
  454.     eorl    #0x80000000,d0
  455. negsf2_z:
  456.     rts            | sigh
  457. # #ifdef L_subsf3
  458. # int
  459. # _subsf3 (a, b)
  460. #      union flt_or_int a, b;
  461. # {
  462. #   union flt_or_int intify;
  463. #   return INTIFY (a.f - b.f);
  464. # }
  465. # #endif
  466.  
  467. .text
  468.     .even
  469. .globl __subsf3
  470. __subsf3:
  471.     tstl    sp@(8)        | kludge.  just negate b and add
  472.     beq    subsf_bz    | zero.  don't bother
  473.     eorl    #0x80000000,sp@(8)    | negate it
  474.     jmp    __addsf3
  475. subsf_bz:
  476.     movel    sp@(4),d0
  477.     rts
  478.  
  479. # #ifdef L_cmpsf2
  480. # int
  481. # _cmpsf2 (a, b)
  482. #      union flt_or_int a, b;
  483. # {
  484. #   union flt_or_int intify;
  485. #   if (a.f > b.f)
  486. #     return 1;
  487. #   else if (a.f < b.f)
  488. #     return -1;
  489. #   return 0;
  490. # }
  491. # #endif
  492.  
  493. .text
  494.     .even
  495. .globl __cmpsf2
  496. __cmpsf2:
  497.     movel    sp@(4),d0
  498.     movel    sp@(12),d1    | get a hi
  499. |
  500. | crockery.  If both neg and not equal, this algorithm lose.  find a better one!
  501. |
  502.     bpl    cmpsf2_p
  503.     tstl    d0
  504.     bpl    cmpsf2_p
  505.     cmpl    d1,d0
  506.     bgt    cmpsf2_m
  507.     blt    cmpsf2_1
  508.     beq    cmpsf2_z
  509. cmpsf2_p:
  510.     cmpl    d1,d0
  511.     beq    cmpsf2_z
  512.     bgt    cmpsf2_1
  513. cmpsf2_m:
  514.     movel    #-1,d0
  515.     rts
  516. cmpsf2_z:
  517.     clrl    d0
  518.     rts
  519. cmpsf2_1:
  520.     movel    #1,d0
  521.     rts            | sigh
  522. # #ifdef L_mulsf3
  523. # int
  524. # _mulsf3 (a, b)
  525. #      union flt_or_int a, b;
  526. # {
  527. #   union flt_or_int intify;
  528. #   return INTIFY (a.f * b.f);
  529. # }
  530. # #endif
  531.  
  532. .text
  533.     .even
  534. .globl __mulsf3
  535. __mulsf3:
  536. |
  537. | multiply.  take the numbers apart.  shift each exponent down to
  538. | 16 bits.  unsigned multiply those.  shift that down to 24 bits.
  539. | exponent is Ea + Eb.
  540. |
  541.  
  542.     link    a6,#-8        | 64 bit accum for mult
  543.     moveml    #0x3F00,sp@-    | save all data registers
  544.     movel    a6@(8),d0    | get a
  545.     beq    mulsf3_z
  546.     movel    a6@(12),d1    | get b
  547.     beq    mulsf3_z
  548.     movel    #23,d6        | shift count
  549.     movel    d0,d2        | get the exponent
  550.     lsrl    d6,d2        | and shift right
  551.     andl    #0xFF,d2
  552.     subl    #126,d2        | offset the exponent
  553.     movel    d1,d3        | get the exponent for b
  554.     lsrl    d6,d3        | and shift right
  555.     andl    #0xFF,d2
  556.     subl    #126,d3        | off set this one too
  557.  
  558.     clrl    d7        | negative result flag
  559.     andl    #0x7FFFFF,d0    | mask a for mantissa
  560.     orl    #0x800000,d0    | and put in hidden bit
  561.     tstl    a6@(8)        | test the original value
  562.     bpl    mulsf3_1    | pos, ok
  563.     eorl    #1,d7        | remember negative
  564. mulsf3_1:
  565.     andl    #0x7FFFFF,d1    | mask b for mantissa
  566.     orl    #0x800000,d1    | ditto
  567.     tstl    a6@(12)        | test ...
  568.     bpl    mulsf3_2
  569.     eorl    #1,d7
  570. mulsf3_2:
  571. |    lsrl    #8,d1        | shift this one down
  572. |    lsrl    #8,d0        | this one too...
  573. |    mulu    d1,d0        | do the multiply
  574.  
  575. |    beq    mulsf3_ret    | zero? ok, just return
  576. |    lsrl    #8,d0        | shift right again
  577.  
  578. |
  579. | we have mantissas as follows:
  580. |
  581. |    |...ah...|...al...|    |...bh...|...bl...|
  582. |
  583. | product is composed as:
  584. |
  585. |            |....al * bl....|
  586. |        |....al * bh....|
  587. |        |....ah * bl....|
  588. |    |....ah * bh....|
  589. |
  590. | then take the 24 bit chunk that's 16 bits in.
  591.  
  592.     movel    d0,d4
  593.     andl    #0xFFFF,d4    | al
  594.     movel    d1,d5
  595.     andl    #0xFFFF,d5    | bl
  596.     mulu    d5,d4        | that's al * bl
  597.     movel    d4,a6@(-4)    | into the accum
  598.     clrl    a6@(-8)        | zap the top part
  599.  
  600.     movel    d0,d4
  601.     andl    #0xFFFF,d4    | al
  602.     movel    d1,d5
  603.     movel    #16,d6        | shift count
  604.     lsrl    d6,d5        | bh
  605.     mulu    d5,d4        | al * bh
  606.     addl    d4,a6@(-6)
  607.  
  608.     movel    d0,d4
  609.     lsrl    d6,d4        | ah
  610.     movel    d1,d5
  611.     andl    #0xFFFF,d5    | bl
  612.     mulu    d5,d4        | ah * bl
  613.     addl    d4,a6@(-6)
  614.  
  615.     movel    d0,d4
  616.     lsrl    d6,d4        | ah
  617.     movel    d1,d5
  618.     lsrl    d6,d5        | bh
  619.     mulu    d5,d4        | ah * bh
  620.     addl    d4,a6@(-8)
  621.  
  622.     movel    a6@(-6),d0    | get the relevant part
  623.     lsrl    #8,d0        | and shift it down
  624.  
  625. mulsf3_norm:
  626.     btst    #23,d0        | normalized?
  627.     bne    mulsf3_ok
  628.     lsll    #1,d0
  629.     subql    #1,d2
  630.     bra    mulsf3_norm
  631.  
  632. mulsf3_ok:
  633.     andl    #0x7FFFFF,d0    | zap hidden bit
  634.     addl    d3,d2        | add Eb to Ea
  635.     addl    #126,d2        | fix offset
  636.     andl    #0xFF,d2    | whack to 8 bits
  637.     movel    #23,d6        | shift count
  638.     lsll    d6,d2        | shift up to right place
  639.     orl    d2,d0        | shove it in
  640.     tstl    d7        | sign neg?
  641.     beq    mulsf3_ret
  642.     orl    #0x80000000,d0    | set sign bit
  643.     bra    mulsf3_ret
  644. mulsf3_z:
  645.     clrl    d0
  646. mulsf3_ret:
  647.     moveml    sp@+,#0x00FC    | snarf back all regs
  648.     unlk    a6
  649.     rts            | sigh
  650. # #ifdef L_divsf3
  651. # int
  652. # _divsf3 (a, b)
  653. #      union flt_or_int a, b;
  654. # {
  655. #   union flt_or_int intify;
  656. #   return INTIFY (a.f / b.f);
  657. # }
  658. # #endif
  659.  
  660. .text
  661.     .even
  662. .globl __divsf3
  663. __divsf3:
  664. |
  665. | divide.  sort of like mult, exc we do shifts and subtracts to
  666. | do the division of the mantissa.  resultant exponent is Ea - Eb.
  667. |
  668.  
  669.     link    a6,#0        | don't need any locals
  670.     moveml    #0x3F00,sp@-    | save all data registers
  671.     movel    a6@(8),d0    | get a
  672.     movel    a6@(12),d1    | get b
  673.     movel    #23,d6        | shift count
  674.     movel    d0,d2        | get the exponent
  675.     lsrl    d6,d2        | and shift right
  676.     andl    #0xFF,d2
  677.     subl    #127,d2        | offset the exponent
  678.     movel    d1,d3        | get the exponent for b
  679.     lsrl    d6,d3        | and shift right
  680.     andl    #0xFF,d3
  681.     subl    #127,d3        | off set this one too
  682.  
  683.     clrl    d7        | negative result flag
  684.     andl    #0x7FFFFF,d0    | mask a for mantissa
  685.     orl    #0x800000,d0    | and put in hidden bit
  686.     tstl    a6@(8)        | test the original value
  687.     bpl    divsf3_1    | pos, ok
  688.     eorl    #1,d7        | remember negative
  689. divsf3_1:
  690.     andl    #0x7FFFFF,d1    | mask b for mantissa
  691.     orl    #0x800000,d1    | ditto
  692.     tstl    a6@(12)        | test ...
  693.     bpl    divsf3_2
  694.     eorl    #1,d7
  695. divsf3_2:
  696. |
  697. | for now, kludge.  shift Ma left and Mb right, then do an unsigned divide
  698. | and shift the result left.  Blech
  699. |
  700.  
  701. |    lsrl    #8,d1        | shift this one down
  702. |    lsll    #7,d0        | this one up
  703. |    divu    d1,d0        | do the divide
  704. |    andl    #0xFFFF,d0    | and mask off cruft
  705.  
  706. |    beq    divsf3_ret    | zero? ok, just return
  707. |    lsll    #8,d0        | shift left again
  708.  
  709. | same sort of trick as long divide, exc it's easier here, cause
  710. | the numbers (mantissas) are already bit-aligned.
  711.  
  712.     clrl    d4        | accumulator
  713.     movel    #0x800000,d5    | bit
  714.     lsll    #7,d0        | buy a little extra accuracy...
  715.     lsll    #7,d1
  716. divsf3_2a:
  717.     cmpl    d1,d0        | compare dividend to divisor
  718.     bmi    divsf3_2b    | nope, no bit here
  719.     orl    d5,d4        | put in the bit
  720.     subl    d1,d0        | and subtract
  721. divsf3_2b:
  722.     lsrl    #1,d1        | slide divisor down
  723.     lsrl    #1,d5        | slide bit down
  724.     bne    divsf3_2a    | and go round again
  725.     movel    d4,d0        | leave the result here
  726.  
  727. divsf3_3:
  728.     btst    #23,d0        | right place yet?
  729.     bne    divsf3_4
  730.     lsll    #1,d0
  731.     subql    #1,d2
  732.     bra    divsf3_3
  733. divsf3_4:
  734.     andl    #0x7FFFFF,d0    | zap hidden bit
  735.     subl    d3,d2        | sub Eb from Ea
  736.     addl    #127,d2        | fix offset
  737.     andl    #0xFF,d2    | whack to 8 bits
  738.     lsll    d6,d2        | shift up to right place
  739.     orl    d2,d0        | shove it in
  740.     tstl    d7        | sign neg?
  741.     beq    divsf3_ret
  742.     orl    #0x80000000,d0    | set sign bit
  743. divsf3_ret:
  744.     moveml    sp@+,#0x00FC    | snarf back all regs
  745.     unlk    a6
  746.  
  747.     rts            | sigh
  748. # #ifdef L_truncdfsf2
  749. # int
  750. # _truncdfsf2 (a)
  751. #      double a;
  752. # {
  753. #   union flt_or_int intify;
  754. #   return INTIFY (a);
  755. # }
  756. # #endif
  757.  
  758. .text
  759.     .even
  760. .globl __truncdfsf2
  761. __truncdfsf2:
  762.     movel    sp@(4),d0
  763.     rts
  764.  
  765. # #ifdef L_extendsfdf2
  766. # double
  767. # _extendsfdf2 (a)
  768. #      union flt_or_int a;
  769. # {
  770. #   union flt_or_int intify;
  771. #   return a.f;
  772. # }
  773. # #endif
  774.  
  775. .text
  776.     .even
  777. .globl __extendsfdf2
  778. __extendsfdf2:
  779.     movel    sp@(4),d0
  780.     clrl    d1
  781.     rts            | sigh
  782.     .even
  783. .text
  784.